package com.acwing.contest;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/4 19:01
 */
public class AC4082子序列 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        writer.write(subsequence(s[0]) + "\n");
        writer.flush();
    }

    private static int subsequence(String s) {
        int answer = 0;
        for (int i = 0; i <= s.length() - 3; i++) {
            for (int j = i + 1; j <= s.length() - 2; j++) {
                for (int k = j + 1; k <= s.length() - 1; k++) {
                    if (s.charAt(i) == 'Q' && s.charAt(j) == 'A' && s.charAt(k) == 'Q') {
                        answer++;
                    }
                }
            }
        }
        return answer;
    }
}
